]> git.r.bdr.sh - rbdr/map/blob - Map/Presentation/Base Components/MapRender/MapAxes.swift
Update license URL
[rbdr/map] / Map / Presentation / Base Components / MapRender / MapAxes.swift
1 import SwiftUI
2
3 struct MapAxes: View {
4
5 let mapSize: CGSize
6 let lineWidth: CGFloat
7 let evolution: Stage
8 let stages: [CGFloat]
9 let stageHeight = CGFloat(100.0)
10 let padding = CGFloat(5.0)
11
12 var body: some View {
13 ZStack(alignment: .topLeading) {
14
15 // Axis Lines
16 Path { path in
17 path.move(to: CGPoint(x: 0, y: 0))
18 path.addLine(to: CGPoint(x: 0, y: mapSize.height))
19 path.addLine(to: CGPoint(x: mapSize.width, y: mapSize.height))
20 path.move(to: CGPoint(x: mapSize.width, y: mapSize.height))
21 path.closeSubpath()
22 }.stroke(Color.map.axisColor, lineWidth: lineWidth * 2)
23
24 // Y Labels
25 Text("Visible").font(.theme.axisLabel).foregroundColor(.map.labelColor).rotationEffect(
26 Angle(degrees: -90.0)
27 )
28 .offset(CGSize(width: -35.0, height: 0.0))
29 Text("Invisible").font(.theme.axisLabel).foregroundColor(.map.labelColor).rotationEffect(
30 Angle(degrees: -90.0)
31 )
32 .offset(CGSize(width: -40.0, height: mapSize.height - 20))
33
34 // X Labels
35
36 Text("Uncharted")
37 .font(.theme.axisLabel)
38 .foregroundColor(.map.labelColor)
39 .frame(width: mapSize.width / 4, height: stageHeight / 2.0, alignment: .topLeading)
40 .offset(CGSize(width: 0.0, height: -stageHeight / 4.0))
41 Text("Industrialised")
42 .font(.theme.axisLabel)
43 .foregroundColor(.map.labelColor)
44 .frame(width: mapSize.width / 4, height: stageHeight / 2.0, alignment: .topLeading)
45 .offset(CGSize(width: mapSize.width - 100.0, height: -stageHeight / 4.0))
46
47 Text(evolution.i)
48 .font(.theme.axisLabel)
49 .foregroundColor(.map.labelColor)
50 .frame(width: w(stages[0]), height: stageHeight, alignment: .topLeading)
51 .offset(CGSize(width: 0.0, height: mapSize.height + padding))
52
53 Text(evolution.ii)
54 .font(.theme.axisLabel)
55 .foregroundColor(.map.labelColor)
56 .frame(width: w(stages[1]) - w(stages[0]), height: stageHeight, alignment: .topLeading)
57 .offset(CGSize(width: w(stages[0]), height: mapSize.height + padding))
58
59 Text(evolution.iii)
60 .font(.theme.axisLabel)
61 .foregroundColor(.map.labelColor)
62 .frame(width: w(stages[2]) - w(stages[1]), height: stageHeight, alignment: .topLeading)
63 .offset(CGSize(width: w(stages[1]), height: mapSize.height + padding))
64
65 Text(evolution.iv)
66 .font(.theme.axisLabel)
67 .foregroundColor(.map.labelColor)
68 .frame(width: mapSize.width - w(stages[2]), height: stageHeight, alignment: .topLeading)
69 .offset(CGSize(width: w(stages[2]), height: mapSize.height + padding))
70 }
71 }
72
73 func w(_ dimension: CGFloat) -> CGFloat {
74 max(0.0, min(mapSize.width, dimension * mapSize.width / 100.0))
75 }
76 }
77
78 #Preview {
79 MapAxes(
80 mapSize: CGSize(width: 200.0, height: 200.0), lineWidth: CGFloat(1.0),
81 evolution: Stage.stages(.general), stages: [25.0, 50.0, 75.0]
82 ).padding(50.0)
83 }